package leetcode;

import java.util.Scanner;

//2019蓝桥杯灵能传输//（无法知道灵能传输最完美的时刻）压轴难题
public class Kundalini {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int h=sc.nextInt();
        int[]num=new int[h];
        for (int i = 0; i <h; i++) {
            int l=sc.nextInt();
            int[]arr=new int[l];
            int max=0,min=0;
            for (int j = 0; j < l; j++) {
                arr[j]=sc.nextInt();
                if(min>arr[j]){
                    min=arr[j];
                }
                if(max<arr[j]){
                    max=arr[j];
                }

            }
            int c=max-min;
            num[i]=zhuanhuang(arr,c);


        }
        for(int a:num){
            System.out.println(a);
        }
    }
    public static int zhuanhuang(int[] arr ,int c){

            int max=arr[0],min=0;
            if(arr.length==2){
                if(max>arr[1]){
                   return max;
                }
                else return arr[1];
            }
            if(arr.length==1){
                return max;
            }
            for (int j = 1; j < arr.length-1; j++) {

                if(arr[j]<0){
                    arr[j]=-arr[j];
                    arr[j+1]=arr[j+1]-arr[j];
                    arr[j-1]=arr[j-1]-arr[j];
                }
                else{
                    arr[j+1]=arr[j+1]+arr[j];
                    arr[j-1]=arr[j-1]+arr[j];
                    arr[j]=-arr[j];
                }
            }
            max=arr[0];
            for (int j = 0; j < arr.length; j++) {
                if(min>arr[j]){
                min=arr[j];
               }
                if(arr[j]<0){
                    arr[j]=-arr[j];
                }
                if(max<arr[1]){
                    max=arr[j];
                }


            }
            if(panduan(max,min,c)){
                return max;
            }else return c;


    }
    public static boolean panduan(int max,int min,int c){
        int s=max-min;
        if(s<=c)return true;
        else return false;
    }

}
